{include file='comdir/head.html'}
<body>
<div class="content">
    <div class="">
        <div class="pos"><a href="#" onClick="javascript :history.back(-1);">返回上一页</a></div>
        <div class="searchBox">
            <form class="form-inline">
                <span>
                日志类型：<select class="form-control" name="logType" id="log-type">
                    <option value="1">登录日志</option>
                    <option value="2">操作日志</option>
                </select>
                </span>
                <span>起始时间：
                    <input type="text" class="form-control" id="start_time" name="start_time">
                </span>
                <span>截止时间：
                    <input type="text" class="form-control" id="end_time" name="end_time">
                </span>
                <span><input type="button" class="form-control btn-blue search-btn" value="搜索"></span>
            </form>
        </div>
    </div>
    <div class="table_list_wrap">
        <div class="table-responsive">
            <table class="table table-bordered table-hover">
                <thead id="theadlist">
                <tr>
                    <th>登录名</th>
                    <th>登录状态</th>
                    <th>登录ip</th>
                    <th>登录时间</th>
                    <th>登录运行文件</th>
                    <th>描述</th>
                </tr>
                </thead>
                <tbody id="log-list">
                {if $data['count'] > 0}
                {foreach $data['list'] as $k=>$v}
                <tr>
                    <td>{$v.username}</td>
                    <td>{$v.resultflag}</td>
                    <td>{$v.loginip}</td>
                    <td>{$v.logintime}</td>
                    <td>{$v.loginurl}</td>
                    <td>{$v.description}</td>
                </tr>
                {/foreach}
                {else}
                <tr>
                    <td colspan="6">--暂无数据--</td>
                </tr>
                {/if}
                </tbody>
            </table>
        </div>
    </div>
    <div class="page-box">
        <div class="page">
            {$data['page']}
        </div>
    </div>
    
</div>
<script src="{$_URL}static/plugins/laydate/laydate.js"></script>
<script>
    //时间选择器
    laydate.render({
        elem: '#start_time'
        ,type: 'datetime'
    });
    laydate.render({
        elem: '#end_time'
        ,type: 'datetime'
    });
    var _URL='{$_URL}';
    {literal}
    $(function(){
        $('#log-type').change(function(){
            var log_type = $("#log-type").val();
            if(log_type=='2'){
                $('#theadlist').html('<tr>\
                <th>操作类型</th>\
                <th>操作状态</th>\
                <th>用户id</th>\
                <th>操作ip</th>\
                <th>描述</th>\
                <th>操作时间</th>\
                </tr>');
            }else{
                $('#theadlist').html('<tr>\
                <th>登录名</th>\
                <th>登录状态</th>\
                <th>登录ip</th>\
                <th>登录时间</th>\
                <th>登录运行文件</th>\
                <th>描述</th>\
                </tr>');
            }
            ajaxpage(1);
        });
        $('.search-btn').click(function () {
            ajaxpage(1);
        });
    });
    function ajaxpage(page) {
        var logType = $("#log-type").val();
        var url='';
        url+=_sousuo.selected('#log-type','logType',-1);
        url+=_sousuo.value('#start_time','start_time');
        url+=_sousuo.value('#end_time','end_time');
        url+="page="+page;
        _ajaxs.post(_URL+"Statistics/logAjax",url,function _return(response){
            if(response.status == 1) {
                ajaxUpdatePager('.page', response.data.page);
                if(logType == '1'){
                    ajaxUpdateTable('#log-list', ['username','resultflag','loginip','logintime','loginurl','description'], response.data.list);
                }else{
                    ajaxUpdateTable('#log-list', ['type','resultflag','userid','userip','description','addtime'], response.data.list);
                }
            }
        },'json');
    }

    /**
     * ajax更新表格数据
     * @param class_id <tbody>的#id或.class
     * @param fileds  需要使用的返回数据列表字段名称
     * @param data_list 返回数据列表
     */
    function ajaxUpdateTable(class_id, fileds, data_list) {
        var item = $(''+class_id),
            tb_list = '';
        if(data_list.length > 0){
            for(var j in data_list){
                tb_list += '<tr>';
                for(var i in fileds){
                    tb_list += '<td>';
                    tb_list += data_list[j][fileds[i]];
                    tb_list += '</td>';
                }
                tb_list += '</tr>';
            }
        }else{
            tb_list += '暂无数据';
        }
        item.html(tb_list);
    }
    /**
     * ajax更新分页栏
     * @param class_id class_id #id或.class
     * @param $pager 返回数据中page
     */
    function ajaxUpdatePager(class_id, pager) {
        var item = $(''+class_id);
        if(pager){
            item.html(pager);
        }else{
            item.html('');
        }
    }
    {/literal}
</script>
</body>
</html>